package com.nuanshui.heatedloan.credit.service.third.party;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.credit.dal.mapper.OptionalAuthMapper;
import com.nuanshui.heatedloan.credit.facade.third.party.JingDongAuthService;
import com.nuanshui.heatedloan.credit.form.CustomerJingDongInfoForm;
import com.nuanshui.heatedloan.credit.vo.CustomerJingDongInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wangxw on 2017/7/8.
 */
@Service(ServiceConstant.JINGDONGAUTHSERVICE)
@Transactional(readOnly=true,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
public class JingDongAuthServiceImpl implements JingDongAuthService {


    @Autowired
    private OptionalAuthMapper optionalAuthMapper;

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public Map<String, Object> jingDongAuth(CustomerJingDongInfoForm customerJingDongInfoForm) {
        this.saveCustomerJingDongInfo(customerJingDongInfoForm);
        Map<String, Object> maps=new HashMap<String,Object>();
        maps.put("authFalg",1);
        maps.put("authDesc","认证成功");
        return maps;
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
    public CustomerJingDongInfoForm saveCustomerJingDongInfo(CustomerJingDongInfoForm customerJingDongInfoForm) {
        optionalAuthMapper.saveCustomerJingDongInfo(customerJingDongInfoForm);
        return customerJingDongInfoForm;
    }


    @Override
    public CustomerJingDongInfoVO loadVOByUserId(String userId){
      return optionalAuthMapper.loadCustomerJingDongInfoVOByUserId(userId);
    }

    public List<CustomerJingDongInfoVO> loadVOAll(){
        List<CustomerJingDongInfoVO>  customerJingDongInfoVO=new ArrayList<CustomerJingDongInfoVO>();
        customerJingDongInfoVO=optionalAuthMapper.loadVOAllJingDong();
        return customerJingDongInfoVO;
    }
}
